﻿
using UnityEngine;
using System.IO;
using UnityEditor;
using SWS;


public class CreatFarmConfigUitl {

    public static void CreatFarmFile(GameObject selectObj, string writePath)
    {
        string fileName = selectObj.name;
        string className = fileName;
        StreamWriter sw = new StreamWriter(Application.dataPath + writePath + className + ".cs");

        sw.WriteLine("using UnityEngine;\nusing System.Collections;\n");
        sw.WriteLine("public class " + className);
        sw.WriteLine("{");
        sw.WriteLine("\tstatic public road_data[] road_Data = new road_data[]{");
        foreach (Transform t in selectObj.transform)
        {
            sw.WriteLine("\t\tnew road_data{");
            sw.WriteLine("\t\t\tdata = new Vector3[]{");
            PathManager road_data = t.GetComponent<PathManager>();
            Vector3[] road_point = WaypointManager.GetCurved(road_data.GetPathPoints());
            for (int i = 0; i < road_point.Length; i++)
            {
                sw.WriteLine("\t\t\t\tnew Vector3(" + road_point[i].x + "f," + road_point[i].y + "f," + road_point[i].z + "f),");
            }
            sw.WriteLine("\t\t\t},");
            sw.WriteLine("\t\t},");
        }
        sw.WriteLine("\t};");
        sw.WriteLine("}");

        sw.Flush();
        sw.Close();
        AssetDatabase.Refresh();        //这里是一个点
    }
}
/*
class FishFarmData
{
    static public road_data[] road_Data = new road_data[]{
        new road_data
        {
            data = new Vector3[]{
                new Vector3(0,0,0),
                new Vector3(0,0,0),
            },
        },
    };
}
*/

